#include "dlg_adduser.h"
#include "ui_dlg_adduser.h"

Dlg_addUser::Dlg_addUser(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dlg_addUser)
{
    ui->setupUi(this);
}

Dlg_addUser::~Dlg_addUser()
{
    delete ui;
}

void Dlg_addUser::setType(bool isAdd, UserInfo info)
{
    m_isAdd = isAdd;
    m_info = info;
    ui->le_username->setText(info.username);
    ui->le_password->setText(info.password);
    ui->le_aut->setText(info.aut);
}

void Dlg_addUser::on_btn_save_clicked()
{
    UserInfo info;
    auto ptr = stumySql::getinstance();
    info.username
        = m_info.username; //要修改的名字传到setType就断了,给了m_info,没传到这个保存按钮,索性赋过来
    info.username = ui->le_username->text();
    info.password = ui->le_password->text();
    info.aut = ui->le_aut->text();
    //ptr->addstu(info);
    if (m_isAdd) {
        ptr->AddUser(info);
    } else {
        ptr->updataUser(info);
    }
    QMessageBox::information(nullptr, "信息", "存储成功");
    this->hide();
}

void Dlg_addUser::on_btn_cancel_clicked()
{
    this->hide();
}
